﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiteStep.DataSources
{
    public static class Proxifier
    {
        private static int nextProxy = 0;

        private static IList<string> proxyDomains = new List<string> {
            "https://litestep-proxy.appspot.com",
            "https://leeflet-proxy.appspot.com"
        };

        public static string Proxify(string address)
        {
            if (string.IsNullOrEmpty(address)) return null;

            var proxifiedAddress = string.Format("{0}?address={1}", proxyDomains[nextProxy], address);

            nextProxy = (nextProxy + 1) % proxyDomains.Count;

            return proxifiedAddress;
        }
    }

    public class Proxy
    {
        private readonly string proxifiedAddress;

        public Proxy(string url)
        {
            proxifiedAddress = Proxifier.Proxify(url);
        }

        public override string ToString()
        {
            return proxifiedAddress;
        }
    }
}
